unit WebAPI_Config;

interface

uses
  SysUtils, Classes;

type
  TCorss_Origin = record
    Allow_Origin: string;
    Allow_Headers: string;
    Allow_Method: string;

    Allow_Credentials: Boolean;
  end;

  TConfig = record
    Host: string;
    Compress: string;
    Port: string;
    JsonFmt: string;
    Charset: string;
    JsonToLower: Boolean;
    HTTPQueueLength: Integer;
    ThreadCount: Integer;
    BasePath: string;
    open_cache: Boolean;
    template_type: string;
    cache_max_age: string;
    MIME: TstringList;
    swagger_open: Boolean;
    Corss_Origin: TCorss_Origin;
  end;

var
  FConfig: TConfig;

procedure Config_Init();

implementation

procedure Init_MIME();
begin
  FConfig.MIME.Values['css'] := 'text/css';
  FConfig.MIME.Values['html'] := 'text/html';
  FConfig.MIME.Values['js'] := 'text/javascript';
  FConfig.MIME.Values['jpeg'] := 'image/jpeg';
  FConfig.MIME.Values['jpg'] := 'image/jpeg';
  FConfig.MIME.Values['png'] := 'image/x-png';
  FConfig.MIME.Values['ico'] := 'image/x-icon';
  FConfig.MIME.Values['gif'] := 'image/gif';
  FConfig.MIME.Values['bmp'] := 'image/bmp';
  FConfig.MIME.Values['xml'] := 'text/xml';
  FConfig.MIME.Values['json'] := 'text/json';
  FConfig.MIME.Values['svg'] := 'image/svg+xml';
  FConfig.MIME.Values['woff'] := 'application/font-woff';
  FConfig.MIME.Values['woff2'] := 'application/font-woff2';
  FConfig.MIME.Values['rtx'] := 'text/richtext';
  FConfig.MIME.Values['zip'] := 'application/x-zip-compressed';
  FConfig.MIME.Values['txt'] := 'text/plain';
  FConfig.MIME.Values['svg'] := 'image/svg+xml';
  FConfig.MIME.Values['svgz'] := 'image/svg+xml';
end;

procedure Config_Init();
begin
  Fconfig.MIME := TStringList.Create;
  Init_MIME();
  FConfig.Host := '+';
  Fconfig.BasePath := ExtractFileDir(ParamStr(0));
  FConfig.template_type := '.html';
  FConfig.open_cache := false;
  FConfig.swagger_open := true;
  if FConfig.Compress = '' then
    FConfig.Compress := 'deflate';
  if FConfig.Port = '' then
    FConfig.Port := '8001';
  if FConfig.HTTPQueueLength = 0 then
    FConfig.HTTPQueueLength := 10;
  if FConfig.ThreadCount = 0 then
    FConfig.ThreadCount := 10;
  if FConfig.Charset = '' then
    FConfig.Charset := 'utf8';
  if FConfig.Corss_Origin.Allow_Origin = '' then
    FConfig.Corss_Origin.Allow_Origin := '*';
  if FConfig.Corss_Origin.Allow_Headers = '' then
    FConfig.Corss_Origin.Allow_Headers := '*';
  if FConfig.Corss_Origin.Allow_Method = '' then
    FConfig.Corss_Origin.Allow_Method := '*';

  if FConfig.cache_max_age = '' then
    FConfig.cache_max_age := '31536000';
end;

initialization
  Config_Init();

finalization
  Fconfig.MIME.Free;

end.

